package com.jtpay.sdk.holder;

import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by Steven on 2017/2/28 0028.
 */

public class BaseViewHolder {
    private SparseArray<View> mViews = new SparseArray<View>();
    private final View mConvertView;

    public View getView(int viewId) {
        View view = mViews.get(viewId);
        if (null == view) {
            view = mConvertView.findViewById(viewId);
            mViews.put(viewId, view);
        }
        return view;
    }

    public BaseViewHolder(View convertView) {
        mConvertView = convertView;
    }

    public BaseViewHolder setText(int viewId, CharSequence value) {
        TextView textView = (TextView) getView(viewId);
        textView.setText(value);
        return this;
    }

    public BaseViewHolder setTextColor(int viewId, int value) {
        TextView textView = (TextView) getView(viewId);
        textView.setTextColor(value);
        return this;
    }
    public BaseViewHolder setTextSize(int viewId, int value) {
        TextView textView = (TextView) getView(viewId);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP,value);
        return this;
    }
    public BaseViewHolder setImageResource(int viewId, int imageResId) {
        ImageView imageView = (ImageView) getView(viewId);
        imageView.setImageResource(imageResId);
        return this;
    }

    public View getConvertView() {
        return mConvertView;
    }
}
